package router

import (
	"go-proxy/config"
	"net/http"
	"strings"
)

type PrefixRouter struct {
}

func NewPrefixRouter() *PrefixRouter {
	return &PrefixRouter{}
}

func (p *PrefixRouter) checkPath(route *config.Route, r *http.Request) bool {
	path := r.URL.Path
	if !route.IgnoreLowercase && strings.HasPrefix(path, route.Path) {
		return true
	}

	lowerPath := strings.ToLower(path)
	lowerRoutePath := strings.ToLower(route.Path)

	return strings.HasPrefix(lowerPath, lowerRoutePath)
}
